package xyz.cerberu.cet.user.configuration;

import io.minio.MinioClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import xyz.cerberu.cet.global.domain.Global;
import xyz.cerberu.cet.user.domain.MinIo;
import xyz.cerberu.cet.user.service.MinIoPictureServiceImpl;
import xyz.cerberu.cet.user.service.PictureService;
import xyz.cerberu.cet.user.service.SimplePictureServiceImpl;

/**
 * @author β世界
 * Created on 8:28
 * @Description 图片服务的设置文件
 */
@Configuration
public class PictureConfig {

    /**
     * @author β世界 on 8:39 2021/4/8
     * 当容器中存在着MinIOClient和MinIO这两个实例的时候，并且MInIO的enable为true的时候创建这个服务
     * @param minioClient:
     * @param minIo:
     * @return xyz.cerberu.cet.user.service.MinIoPictureServiceImpl
     **/
    @Bean
    @ConditionalOnProperty(name = {"minio.enable"},havingValue = "true")
    @ConditionalOnBean(value = {MinioClient.class,MinIo.class})
    public MinIoPictureServiceImpl minIoPictureService(MinioClient minioClient, MinIo minIo){
        return new MinIoPictureServiceImpl(minioClient,minIo);
    }

    /**
     * @author β世界 on 8:45 2021/4/8
     * 基本的服务实现，当容器中不存在一个pictureService的时候，就创建这个服务
     * @param global: 全局的对象
     * @return xyz.cerberu.cet.user.service.SimplePictureServiceImpl
     **/
    @Bean
    @ConditionalOnMissingBean(value = PictureService.class)
    public SimplePictureServiceImpl simplePictureService(Global global){
        return new SimplePictureServiceImpl(global);
    }

}
